JSF/Facelets: set `action` attribute to a dynamically evaluated string

Posted by harto on Stack Overflow See other posts from Stack Overflow or by harto
Published on 2009-08-06T07:35:48Z Indexed on 2010/05/11 23:54 UTC
Read the original article Hit count: 316

Filed under:
|
|
|

In my JSF/Facelets application, I want to dynamically generate a breadcrumb trail from a list of page IDs using a custom tag:

<foo:breadcrumbs trail="foo,bar,baz"/>

This should generate something like:

<h:commandLink action="foo" ... />
<h:commandLink action="bar" ... />
<!-- (etc.) -->

My code looks something like this:

<ui:repeat value="#{fn:split(trail, ',')}" var="key">
    <h:commandLink action="#{key}" ... /> 
</ui:repeat>

The problem with this code is that #{key} is interpreted as a method binding. However, I just want the string value of #{key} to be returned as the navigation outcome. How can I achieve this?


The only thing I could think of was creating a dummy managed-bean that has an outcome field and an action handler, and invoke it like so:

<h:commandLink action="#{dummy.click}" ...>
    <f:setPropertyActionListener target="#{dummy.outcome}" value="#{key}" />
</h:commandLink>

with the dummy class defined like so:

public class Dummy {

    private String outcome;

    public String click() {
        return outcome;
    }

    public void setOutcome(String outcome) {
        this.outcome = outcome;
    }

    public void getOutcome() {
        return outcome;
    }
}

That seems ugly though, and I don't know if it would work.

© Stack Overflow or respective owner

Related posts about jsf

Related posts about facelets